package file;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-04-19
 * Time: 16:29
 */
//按照字符来读
public class Demo6 {
    public static void main(String[] args) {
        try(Reader reader = new FileReader("d:/test.txt")) {
            //按照字符来读
            while(true) {
                char[] buffer = new char[1024];
                int len = reader.read(buffer);//实际读到的字符个数
                if(len == -1) {
                    break;
                }
                /*for (int i = 0; i < len; i++) {
                    System.out.println(buffer[i]);
                }*/
                String str = new String(buffer,0,len);
                System.out.println(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
